#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;




//                                                      һά����ǰ׺��ģ��
int main()
{
    //1.��ֵ���뵽ԭʼ����
    int n = 0, q = 0;
    cin >> n >> q;
    vector<int> arr(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    //2.����dp����
    vector<long long int> dp(n + 1);
    for (int i = 1; i <= n; i++)
        dp[i] = dp[i - 1] + arr[i];
    //3.ʹ��dp����
    int l = 0, r = 0;
    while (q--)
    {
        cin >> l >> r;
        cout << dp[r] - dp[l - 1] << endl;
    }
}


//                                                    ��ά����ǰ׺��ģ��
//int main()
//{
//    //1.��ֵ���뵽ԭʼ����
//    int n = 0, m = 0, q = 0;
//    cin >> n >> m >> q;
//    vector<vector<int>> arr(n + 1, vector<int>(m + 1));
//    for (int i = 1; i <= n; i++)
//        for (int j = 1; j <= m; j++)
//            cin >> arr[i][j];
//    //2.����dp����
//    vector<vector<long long int>> dp(n + 1, vector<long long int>(m + 1));
//    for (int i = 1; i <= n; i++)
//        for (int j = 1; j <= m; j++)
//            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + arr[i][j] - dp[i - 1][j - 1];
//    //3.ʹ��dp����
//    int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
//    while (q--)
//    {
//        cin >> x1 >> y1 >> x2 >> y2;
//        cout << dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1] << endl;
//    }
//}


//                                                      Ѱ������������±�
class Solution
{
public:
    int pivotIndex(vector<int>& nums)
    {
        //1.����ǰ׺������
        int n = nums.size();
        vector<int> f(n);
        f[0] = 0;
        for (int i = 1; i < n; i++)
            f[i] = f[i - 1] + nums[i - 1];

        //2.�����׺������
        vector<int> g(n);
        g[n - 1] = 0;
        for (int i = n - 2; i >= 0; i--)
            g[i] = g[i + 1] + nums[i + 1];

        //3.ʹ��
        for (int i = 0; i < n; i++)
        {
            if (f[i] == g[i])
                return i;
        }
        return -1;

    }
};

//                                                      ��Ϊk��������
class Solution
{
public:
    int subarraySum(vector<int>& nums, int k)
    {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int sum = 0, count = 0;
        for (auto e : nums)
        {
            sum += e;
            if (hash.count(sum - k))
                count += hash[sum - k];
            hash[sum]++;
        }
        return count;
    }
};


//                                              �Ϳɱ�K������������
class Solution
{
public:
    int subarraysDivByK(vector<int>& nums, int k)
    {
        unordered_map<int, int> hash;
        int sum = 0, rest = 0, count = 0;
        hash[0] = 1;
        for (auto e : nums)
        {
            sum += e;
            rest = (sum % k + k) % k;
            //����[0,i-1]���俴������ == rest��
            //����� ++ ���ж�if�Ļ����Ͱ�i���λ��Ҳ���ȥ��
            if (hash.count(rest))
                count += hash[rest];
            hash[rest]++;

        }
        return count;
    }
};


//                                                  ��������
class Solution
{
public:
    int findMaxLength(vector<int>& nums)
    {
        int sum = 0, ret = 0;
        unordered_map<int, int> hash; //��ǰ׺�� ������ĳ���
        hash[0] = -1;
        //1.�Ȱ�0 -> 1
        for (int i = 0; i < nums.size(); i++)
        {
            if (nums[i] == 0)
                nums[i] = -1;

            sum += nums[i]; // ��ǰλ�õ�ǰ׺��
            //���뵱ǰλ�õ�ǰ׺��֮ǰ��
            //����Ҫ�ȿ���ǰ����û�к�һ����
            //�еĻ�������ret����Ϊǰ���� �ʹ���ǰһ���ֶ̣����ҵ�K������͸����������Ҫ���£�
            if (hash.count(sum))
                ret = max(ret, i - hash[sum]);
            else
                hash[sum] = i;
        }
        return ret;

    }
};


//                                                  矩阵区域和
class Solution
{
public:
    vector<vector<int>> matrixBlockSum(vector<vector<int>>& mat, int k)
    {
        int m = mat.size(), n = mat[0].size();
        //dp多加一行，多加一列
        vector<vector<int>> dp(m + 1, vector<int>(n + 1));
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++)
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + mat[i - 1][j - 1] - dp[i - 1][j - 1];

        //answer
        vector<vector<int>> answer(m, vector<int>(n));
        for (int i = 0; i < m; i++)
            for (int j = 0; j < n; j++)
            {
                int x1 = max(0, i - k) + 1, y1 = max(0, j - k) + 1;
                int x2 = min(m - 1, i + k) + 1, y2 = min(n - 1, j + k) + 1;
                answer[i][j] = dp[x2][y2] - dp[x1 - 1][y2] - dp[x2][y1 - 1] + dp[x1 - 1][y1 - 1];
            }
        return answer;
    }
};